//
//  ZJCourseTeacherView.m
//  ZhongWangYuanApp
//
//  Created by ZJ on 2018/6/2.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "ZJCourseTeacherView.h"

@interface ZJCourseTeacherView ()
/** title */
@property (nonatomic, strong) UILabel *titleLabel;
/** 头像 */
@property (nonatomic, strong) UIImageView *headerImage;
/** 姓名 */
@property (nonatomic, strong) UILabel *namelabel;
/** 职位 */
@property (nonatomic, strong) UILabel *positionLabel;
/** 简介 */
@property (nonatomic, strong) UILabel *contentLabel;
@end
@implementation ZJCourseTeacherView

- (instancetype)init_title:(NSString *)title
{
    self = [super init];
    if (self) {
        [self initUIWithTitlte:title];
    }
    return self;
}

- (void)initUIWithTitlte:(NSString *)title{
    self.backgroundColor = [UIColor themeWhiteColor];
    [self addSubview:self.titleLabel];
    [self addSubview:self.headerImage];
    [self addSubview:self.namelabel];
    [self addSubview:self.positionLabel];
    [self addSubview:self.contentLabel];
    
    self.titleLabel.text = title;
    
    self.titleLabel.sd_layout
    .topSpaceToView(self, 12 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 12 * [UIScreen zj_screenWScale])
    .widthIs([UIScreen zj_screenWith] - 24 * [UIScreen zj_screenWScale])
    .heightIs([NSString heightWithTextFont:self.titleLabel.font]);
    
    self.headerImage.sd_layout
    .topSpaceToView(self.titleLabel, 10 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self, 35 * [UIScreen zj_screenHScale])
    .widthIs(65 * [UIScreen zj_screenWScale])
    .heightIs(100 * [UIScreen zj_screenHScale]);
    
    self.namelabel.sd_layout
    .topSpaceToView(self.titleLabel, 25 * [UIScreen zj_screenHScale])
    .leftSpaceToView(self.headerImage, 32 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self, 12 * [UIScreen zj_screenWScale])
    .heightIs([NSString heightWithTextFont:self.namelabel.font]);
    
    self.positionLabel.sd_layout
    .topSpaceToView(self.namelabel, 18 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.namelabel)
    .widthIs([UIScreen zj_screenWith] - (100 + 12 + 32) * [UIScreen zj_screenWScale]);
    
    self.contentLabel.sd_layout
    .topSpaceToView(self.headerImage, 20 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.titleLabel)
    .widthIs([UIScreen zj_screenWith] - 24 * [UIScreen zj_screenWScale]);

    [self setupAutoHeightWithBottomView:self.contentLabel bottomMargin:12 * [UIScreen zj_screenHScale]];
   
}


- (void)setModel:(ZJCourseTeacherModel *)model{
    _model = model;
    
    [self.headerImage sd_setImageWithURL:CREATEURL(model.photo_servername) placeholderImage:PlaceholderBigHeaderImage];
    
    self.namelabel.text = [NSString isNilStringReturnString:model.name];
    self.positionLabel.text = [NSString isNilStringReturnString:model.description_D];
    self.contentLabel.keywordsColor = self.backgroundColor;
    self.contentLabel.text = [NSString stringWithFormat:@"尚錕%@",[NSString  string:model.comment isNilStringReturnDeftString:@""]];
    self.contentLabel.sd_layout
    .topSpaceToView(self.headerImage, 20 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.titleLabel)
    .widthIs([UIScreen zj_screenWith] - 24 * [UIScreen zj_screenWScale])
    .heightIs([self.contentLabel getLableSizeWithMaxWidth:self.contentLabel.width].height);
    [self.contentLabel updateLayout];
    
    self.positionLabel.sd_layout
    .topSpaceToView(self.namelabel, 18 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.namelabel)
    .widthIs([UIScreen zj_screenWith] - (100 + 12 + 32) *[UIScreen zj_screenWScale])
    .heightIs([self.positionLabel getLableSizeWithMaxWidth:self.positionLabel.width].height);
    [self.positionLabel updateLayout];
}

#pragma mark - getter
- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor zj_colorWithHexString:@"626262"];
        _titleLabel.font = LYPBOLDFONT(18);
    }
    return _titleLabel;
}

- (UIImageView *)headerImage{
    if (_headerImage == nil){
        _headerImage = [UIImageView new];
        _headerImage.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _headerImage;
}

- (UILabel *)namelabel{
    if (_namelabel == nil){
        _namelabel = [UILabel new];
        _namelabel.font = LYPBOLDFONT(20);
        _namelabel.textColor = self.titleLabel.textColor;
    }
    return _namelabel;
}

- (UILabel *)positionLabel{
    if (_positionLabel == nil){
        _positionLabel  = [UILabel new];
        _positionLabel.font = self.contentLabel.font;
        _positionLabel.textColor = self.contentLabel.textColor;
        _positionLabel.numberOfLines = 2;
    }
    return _positionLabel;
}

- (UILabel *)contentLabel{
    if (_contentLabel == nil){
        _contentLabel = [UILabel new];
        _contentLabel.textColor = [UIColor zj_colorWithHexString:@"626262"];
        _contentLabel.font = LYPFONT(15);
        _contentLabel.numberOfLines = 0;
        _contentLabel.characterSpace = 1;
        _contentLabel.lineSpace = 8 * [UIScreen zj_screenHScale];
        _contentLabel.keywordsArray = @[@"尚錕"];
        _contentLabel.keywordsFont = _contentLabel.font;
    }
    return _contentLabel;
}


@end
